@echo off
chcp 65001 >nul

:: 变量定义
set verbose=1
if "%~1"=="/s" set verbose=0
@REM set JAVA_HOME="%cd%\jdk-17.0.8"
set JAVA_HOME="E:\\git_code\\windows_wvp_offline_install\\Java\\jdk"


:: 检查JAVA_HOME是否已设置
if %verbose% equ 1 echo 正在检查JAVA_HOME环境变量...
if defined JAVA_HOME (
    if %verbose% equ 1 echo JAVA_HOME已设置为: %%JAVA_HOME%%
    goto check_path
) else (
    if %verbose% equ 1 echo JAVA_HOME环境变量未设置
)

:: 设置JAVA_HOME
setx JAVA_HOME %JAVA_HOME%
if %verbose% equ 1 echo 已设置JAVA_HOME: %JAVA_HOME%

:check_path
:: 检查PATH是否已包含JDK路径
if %verbose% equ 1 echo 正在检查PATH环境变量...
if %verbose% equ 1 echo 当前PATH值: %%PATH%%
echo %%PATH%% | find "%%JAVA_HOME%%\bin" >nul
if %errorlevel% equ 0 (
    if %verbose% equ 1 echo PATH中已包含JDK路径: %%JAVA_HOME%%\bin
    goto end
) else (
    if %verbose% equ 1 echo PATH中未找到JDK路径
)

:: 添加JDK路径到PATH
if %verbose% equ 1 echo 正在将JDK路径添加到PATH...
setx PATH "%%PATH%%;%%JAVA_HOME%%\bin"
if %verbose% equ 1 echo 已将JDK路径添加到PATH: %%JAVA_HOME%%\bin
if %verbose% equ 1 echo 更新后的PATH值: %%PATH%%

:: 立即更新当前会话的环境变量
set PATH=%%PATH%%;%%JAVA_HOME%%\bin

:end